<!DOCTYPE html>
<html>
  <head>
    <title>订单物流管理</title>
    <include file='public/head'>
    <style>
        .layui-legend-size{font-size:14px !important;}
        .layui-nopadding{padding:0 !important;}
        .layui-overflow{overflow:auto;}
        .layui-nomargin{margin: 0 !important;}
        .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
        .layui-input{height:30px !important; }
        .layui-form-search-item .layui-inline{margin-bottom: 5px;} 
        .layui-form-search-item label{margin-left: 15px;}
        .layui-table-page {padding: 7px 0px 0px;}
        .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
    </style>
</head>
<body>
  <!-- layui-tab开始 -->
  <div class="layui-tab" lay-fliter="demo-tab">
    
    <!-- 内容开始 -->
    <div class="layui-card">
        <div class="layui-card-header layui-bg-gray layui-bottom">
            <form class="layui-form table-bar" id="v"  method="post">
            <div class="layui-input-inline" style="margin:3px; width:20%;">
            <select type="text" name="code" autocomplete="off" placeholder="选择物流公司"  lay-verify="required" class="layui-select" lay-search>
                <volist name="logistics" id="vo">
                <option value="{$vo.code}" >{$vo.company}</option>
                </volist>
            </select>
            </div>
            <div class="layui-input-inline" style="margin:3px; width: 65%;">
            <input type="text" class="layui-input" name="num" value="" placeholder="连号“-”隔开、散号“,”英文逗号隔开。例如：1000-1010,1020,1030">
            </div>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal " style="font-weight:800; width:12%;" onclick="AddLogistics()" >录入</button>
            </form>
        </div>
   

        <!-- 搜索栏开始 -->
        <fieldset class="layui-elem-field layui-field-title layui-field-padding">
            <legend class="layui-legend-size">搜索框</legend>
            <form id="f" method="post" class="layui-form table-bar">
                <div class="layui-form-search-item">

                    <div class="layui-inline" >
                        <div class="layui-input-inline" style="width: 100px;">
                            <select name="search[type]" lay-verify="" class="layui-input">
                                <option value="1" <eq name="search.type" value="1">selected</eq> >订单编号</option>
                                <option value="2" <eq name="search.type" value="2">selected</eq> >物流单号</option>
                            </select>   
                        </div>

                        <div class="layui-input-inline" style="width: 200px;">
                            <input type="text" name="search[title]" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{$search.title}" style="width: 200px;">
                        </div>
                    </div>

                    
                    <div class="layui-input-inline" >
                        <div class="layui-inline">
                            <select type="text" name="search[code]" autocomplete="off" placeholder="选择物流公司"  lay-verify="required" class="layui-select" lay-search>
                                <option value="">选择物流公司</option>
                                <volist name="logistics" id="vo">
                                <option value="{$vo.code}" >{$vo.company}</option>
                                </volist>
                            </select>
                        </div>   
                    </div>
                        
                    <div class="layui-inline">
                    <div class="layui-input-inline" style="width: 100px;">
                        <select name="search[status]" lay-verify="" class="layui-input" placeholder="选择状态" >
                            <option value="" >选择状态</option>
                            <option value="1" <eq name="search.status" value="1">selected</eq> >未使用</option>
                            <option value="2" <eq name="search.status" value="2">selected</eq> >已使用</option>
                        </select>
                    </div></div>
                            
                    <div class="layui-inline">
                    <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
                    </div>
                    
                </div>
            </form>
        </fieldset>
        <!-- 搜索栏结束 -->
    
    <!-- 数据表格开始 -->
    <form method="post" id="f">
    <table class="layui-table layui-nomargin">
        <thead>
            <tr>
                <th>快递公司编码</th>
                <th>物流单号</th>
                <th>订单编号</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            
        </thead>
        <tbody>
            <volist  name="data" id="vo">
                <tr lay-fliter="test3">
                    <td>{$vo.code}</td>
                    <td>{$vo.logistics_code}</td>
                    <td>{$vo.order_num ? $vo.order_num : '/'}</td>
                    <td>{$vo.status == 1 ? "未使用":"已使用";}</td>
                    <td>
                        <div class="layui-btn-group">
                        <button type="button" onclick="edit({$vo.id})"class="layui-btn layui-btn-primary layui-btn-xs" title="编辑"><i class="layui-icon">&#xe642;</i></button>
                        <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs delete-btn" title="删除"><i class="layui-icon">&#xe640;</i></button>
                        </div>
                    </td>
                </tr>
            </volist>
        </tbody>
    </table>



    </form>
    <!-- 数据表格结束 -->
    </div>
    <!-- 内容结束 -->
    
  </div>
  <!-- layui-tab开始 -->
</body>

<include file="public/scripts"/>
<script>

function AddLogistics(){

    var data = $('#v').serialize();
    $.ajax({
        url:"{:cmf_plugin_url('Logistics://logistics_order/addLogisticsOrder')}",
        type:'post',
        data:data,
        success:function(data){
            console.log(data);
            if(data.status == 'success'){
                layer.msg(data.message,{time:1200,icon:1},function(){
                    window.location.reload();
                });
            }else{
                layer.msg(data.message,{time:1200,icon:5});
            }

        },
        error:function(data){
            layer.msg('系统错误',{time:1200,icon:5});
        }
    })
}

/**
 * 编辑
 */
function edit(id)
{
    layer.open({
        title:'修改发货信息',
        type: 2,
		shadeClose: true,//是否点击遮罩关闭
        btn:["确定","取消"],
        area: ['800px','400px'],
        content: "{:cmf_plugin_url('Logistics://logistics_order/editLogisticsOrder')}?id="+id,
        yes:function(index,layero){
           //子页面的请求操作都放子页面
           var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.tijiao();
        },btn2:function(index, layero){
			}
    })
}



/**
 * 删除
 */
 $('.delete-btn').on('click',function(){
        // var id_str = $('input[type=checkbox]:checked').map(function(){return this.value}).get().join(',');
        let id = $(this).data('id');
        // if(id == undefined) id = id_str;
        //询问
        layer.confirm('确定要删除吗？',{icon:3,title:'提示',btn:['删除','取消']}
        ,function(index,layero){
            $.ajax({
                url:"{:cmf_plugin_url('Logistics://logistics_order/delete')}",
                type:'post',
                data:{id:id},
                success:function(data){
                    let icon = ( data.code == 200 ) ? 1 : 5 ;
                    layer.msg( data.message , { time:1200 , icon:icon },function(){
                        window.location.reload();
                    });
                },
                error:function(data){
                    console.log(data);
                    layer.msg('系统错误',{time:1200,icon:5});
                }
            })   
        },function(index){});
       
    })

</script>
</html>